using System;

namespace OpenWaves.Caching
{
    public static class ConcurrentCacheEntry
    {
        public static ConcurrentCacheEntry<T> FromValue<T>(T value) where T : class
        {
            return new ConcurrentCacheEntry<T>(value);
        }

        public static ConcurrentCacheEntry<T> FromValue<T>(T value, DateTime absoluteExpiration) where T : class
        {
            return new ConcurrentCacheEntry<T>(value, absoluteExpiration);
        }

        public static ConcurrentCacheEntry<T> FromValue<T>(T value, TimeSpan absoluteExpiration) where T : class
        {
            return new ConcurrentCacheEntry<T>(value, absoluteExpiration == TimeSpan.MaxValue ? DateTime.MaxValue : Time.Now + absoluteExpiration);
        }
    }

    public class ConcurrentCacheEntry<T>
    {
        public readonly T Value;
        public readonly DateTime? AbsoluteExpiration;

        public ConcurrentCacheEntry(T value)
        {
            this.Value = value;
        }

        public ConcurrentCacheEntry(T value, DateTime absoluteExpiration)
        {
            this.Value = value;
            this.AbsoluteExpiration = absoluteExpiration;
        }

    }

}